<template>
   <div class="goods-list">
    <!-- 编程式导航 window.location.href -->
    <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDetail(item.id)">
      <img :src="item.img_url" alt>
      <h3 class="goods-title">{{item.title}}</h3>
      <div class="info">
        <p class="price">
          <span class="now">￥{{item.market_price}}</span>
          <span class="old">￥{{item.sell_price}}</span>
        </p>
        <p class="sale">
          <span>热带中</span>
          <span>剩余{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>

    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
    data() {
        return {
           goodsList:[] ,
           pageindex:1

        }
    },
    methods: {
        getGoodsList(){
            this.$http.get('api/getgoods?pageindex='+this.pageindex).then(function (res) {  
                if(res.body.status==0){
                    this.goodsList=this.goodsList.concat(res.body.message)
                }
            })
        },
        getMore(){
            this.pageindex++
            this.getGoodsList()
        },
        goDetail(id){
            this.$router.push({name:'goodsinfo',params:{id:id}})
        }


    },
    created() {
        this.getGoodsList()
    },
}
</script>   

<style lang="scss" scoped>
.goods-list {
  padding: 0 7px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

  .goods-item {
    margin: 3px 0;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    width: 49%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    img {
      width: 100%;
    }
    .goods-title {
      font-size: 15px;
     
    }
    .info {
      background: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          font-size: 16px;
          font-weight: 800;
          color: red;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 12px;
        }
      }
    }
    .sale{
        display: flex;
        justify-content: space-between;
    }
  }
}
</style>

